from sqlalchemy import func
from sqlalchemy.dialects.postgresql import JSONB
from models.engine import db
from models.types import StringUUID

class MHotSearch(db.Model):
    """
    热搜
    """
    __tablename__ = "sp_hot_search"
    __table_args__ = (
        db.PrimaryKeyConstraint("id", name="sp_hot_search_pkey"),
        db.Index("sp_hot_search_status_idx", "status"),
    )
    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True,comment="ID")
    shop_id = db.Column(StringUUID, nullable=True,comment="店铺ID:null为平台级")
    title = db.Column(db.String(128), nullable=False,comment="标题")
    content = db.Column(db.String(255), nullable=False,comment="内容")
    status = db.Column(db.Boolean(),server_default=db.text("true"), nullable=False,comment="上线状态")
    seq = db.Column(db.Integer, nullable=False,server_default=db.text('0'),comment="排序")
    created_at = db.Column(db.TIMESTAMP(timezone=False),server_default=func.current_timestamp(), nullable=False,comment="创建时间")
    created_by = db.Column(StringUUID, nullable=False,comment="创建人")

class MIndexImg(db.Model):
    __tablename__ = "sp_index_img"
    __table_args__ = (
        db.PrimaryKeyConstraint('id',name='sp_index_img_pkey'),
    )
    id = db.Column(db.BigInteger,autoincrement=True, primary_key=True)
    shop_id = db.Column(StringUUID, nullable=False,comment="店铺ID")
    img_file_id = db.Column(StringUUID, nullable=False,comment="图片文件ID")
    descrip = db.Column(db.String(255),server_default=db.text("''"), nullable=True,comment="描述")
    title = db.Column(db.String(255), nullable=True,comment="标题")
    link = db.Column(db.String(255), nullable=True,comment="链接")
    status = db.Column(db.Boolean, nullable=False,server_default=db.text("true"),comment="状态:true:正常,false:禁用")
    seq = db.Column(db.Integer, nullable=True,server_default=db.text('0'),comment="排序")
    relation_prod = db.Column(StringUUID, nullable=True,comment="关联产品ID")
    idx_type = db.Column(db.SmallInteger, nullable=True,server_default=db.text('0'),comment="索引类型")
    created_at = db.Column(db.TIMESTAMP(timezone=False),server_default=func.current_timestamp(), nullable=False,comment="创建时间")
    created_by = db.Column(StringUUID, nullable=False,comment="创建人")

class MSysLog(db.Model):
    __tablename__ = "sp_sys_log"
    __table_args__ = (
        db.PrimaryKeyConstraint('id',name='sp_syslog_pkey'),
    )
    id = db.Column(db.BigInteger,autoincrement=True, primary_key=True)
    account_id = db.Column(StringUUID, nullable=False,comment="用户ID")
    user_name = db.Column(db.String(64), nullable=False,comment="用户名")
    action = db.Column(db.String(64), nullable=False,comment="操作")
    method = db.Column(db.String(64), nullable=False,comment="方法")
    params = db.Column(JSONB,nullable=True,comment="参数")
    created_at = db.Column(db.TIMESTAMP(timezone=False),server_default=func.current_timestamp(), nullable=False,comment="创建时间")
    ip_addr = db.Column(db.String(64), nullable=True,comment="IP地址")
